package org.superheroes.androidclient.gui;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TwoLineListItem;

/**
 * 
 * @author Jeffrey Goudzwaard
 * @author Davin Terrizi
 * @version 1.0
 *
 */
@SuppressWarnings( "deprecation" )
public class DiscoveryAdapter extends BaseAdapter
{

	ArrayList<Filmpje>	filmpjes;
	Context				context;

	public DiscoveryAdapter( Context context, ArrayList<Filmpje> filmpjes )
	{
		this.filmpjes = filmpjes;
		this.context = context;
	}

	@Override
	public int getCount()
	{
		return filmpjes.size();
	}

	@Override
	public Object getItem( int position )
	{
		return filmpjes.get( position );
	}

	@Override
	public long getItemId( int position )
	{
		return filmpjes.get( position ).hashCode();
	}

	@Override
	public View getView( int position, View convertView, ViewGroup parent )
	{

		TwoLineListItem row;
		if ( convertView == null )
		{
			LayoutInflater inflater = ( LayoutInflater ) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
			row = ( TwoLineListItem ) inflater.inflate( android.R.layout.simple_list_item_2, null );
		}
		else
		{
			row = ( TwoLineListItem ) convertView;
		}

		row.getText1().setText( filmpjes.get( position ).fileName );
		row.getText2().setText( filmpjes.get( position ).machine );

		return row;

	}

}
